package com.hyk.commonLib.common.utils.dataCache;

import android.content.Context;

import com.orhanobut.hawk.Storage;
import com.tencent.mmkv.MMKV;

/**
 * Created by 贺玉琨 on 2020/3/20.
 */
public class MmkvStorage implements Storage {

    private static final String MMAP_ID = "MmkvStorage";

    public MmkvStorage(Context c) {
        MMKV.initialize(c);
    }

    private MMKV getMmkv() {
        return MMKV.mmkvWithID(MMAP_ID, MMKV.MULTI_PROCESS_MODE);
    }

    @Override
    public <T> boolean put(String key, T value) {
        getMmkv().putString(key, String.valueOf(value));
        return false;
    }

    @Override
    public <T> T get(String key) {
        return (T) getMmkv().getString(key, null);
    }

    @Override
    public boolean delete(String key) {
        return false;
    }

    @Override
    public boolean deleteAll() {
        getMmkv().clearAll();
        return true;
    }

    @Override
    public long count() {
        return getMmkv().count();
    }

    @Override
    public boolean contains(String key) {
        return getMmkv().contains(key);
    }
}
